package com.lesama.frame;

import javax.swing.*;
import javax.swing.text.IconView;
import java.awt.*;

/*
* Jlabel组件：
*   new JLabel(String string) 创建文本组件
*   new JLabel(Icon icon) 创建图片组件, 其中Icon是一个接口，通过实现类ImageIcon创建对象传入
*   JLabel组件后来创建的是从下面放置，也就是说先创建的组件会覆盖后创建的组件
* */

public class FrameTest3 {
    public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setSize(800, 500);
        frame.setLayout(null);
        frame.setTitle("放置JLabel组件");
        // JLabel创建文本内容
        JLabel label1 = new JLabel("文本内容1");
        label1.setBounds(50, 50, 100, 50);
        frame.getContentPane().add(label1);
        JLabel label2 = new JLabel("文本内容2");
        label2.setBounds(150, 50, 100, 50);
        frame.getContentPane().add(label2);
        // JLabel创建图片内容
        JLabel labelImg2 = new JLabel(new ImageIcon("D:\\project\\java-learning\\java-advanced-codes\\day03\\image\\2.png"));
        labelImg2.setBounds(50, 100, 100, 100);
        frame.getContentPane().add(labelImg2);
        JLabel labelImg3 = new JLabel(new ImageIcon("D:\\project\\java-learning\\java-advanced-codes\\day03\\image\\3.png"));
        labelImg3.setBounds(150, 100, 100, 100);
        frame.getContentPane().add(labelImg3);
        JLabel labelImgSuccess = new JLabel(new ImageIcon("D:\\project\\java-learning\\java-advanced-codes\\day03\\image\\win.png"));
        labelImgSuccess.setBounds(50, 200, 266, 88);
        frame.getContentPane().add(labelImgSuccess);
        frame.setVisible(true);
    }
}
